package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"time"
)

/*
@Project        :   tmp_report
@FileName       :   tmpControllers.go
@Author         :   tangchaolizi
@Datetime       :   2020/7/27 3:33 下午
@Software       :   GoLand
@Show           :
*/

type TmpController struct {
	beego.Controller
}

// 体温填报信息首页展示
func (c *TmpController) Get() {
	c.Data["ctime"] = time.Now().Format("2006-01-02") // 获取当前日期
	username := c.GetSession("Username")              // 获取session
	c.Data["IsLogin"] = username
	c.TplName = "tmp/report.html"
}

// time.Now().Format("2006-01-02")
// 获取温度填报信息
func (c *TmpController) GetTmp() {
	var TmpInfos TmpJson
	o := orm.NewOrm()
	SelectTime := c.GetString("riqixuanze")
	sq := "select * from tmp_info where report_time like '" + SelectTime + "%'" // 构建sql语句
	num, err := o.Raw(sq).QueryRows(&TmpInfos.Data)
	if err == nil {
		fmt.Println(err, num)
	}
	beego.Info(TmpInfos)
	TmpInfos.Code = 0
	TmpInfos.Status = true
	TmpInfos.Msg = "查询成功"
	c.Data["json"] = TmpInfos
	c.ServeJSON()
}

// 获取当天填报人员信息
func (c *TmpController) GetCurTmp() {
	var TmpInfos TmpJson
	o := orm.NewOrm()
	CurrentDate := time.Now().Format("2006-01-02")
	sq := "select * from tmp_info where report_time like '" + CurrentDate + "%'" // 构建sql语句
	num, err := o.Raw(sq).QueryRows(&TmpInfos.Data)                              // 信息传入结构体TmpInfos
	if err == nil {
		fmt.Println(err, num)
	}
	beego.Info(TmpInfos)
	TmpInfos.Code = 0
	TmpInfos.Status = true
	TmpInfos.Msg = "查询成功"
	c.Data["json"] = TmpInfos
	c.ServeJSON()
}
